package com.gui;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.plaf.DimensionUIResource;

import com.metier.EntreesMetier;
import com.metier.ProjetMetier;

/**
 * 
 * @author moussa
 */
public class PanAjouterEntrees extends javax.swing.JPanel {
	EntreesMetier entreeMetier;

	/**
	 * Creates new form PanelAjouterSorties
	 */
	public PanAjouterEntrees() {
		entreeMetier = new EntreesMetier();
		// initComponents();
	}

	public PanAjouterEntrees(JButton boutonAnnuler) {
		entreeMetier = new EntreesMetier();
		initComponents(boutonAnnuler);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents(JButton buttonAnnulers) {
		setBackground(new java.awt.Color(128, 130, 133));
		setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1,
				new java.awt.Color(123, 153, 255)));
		setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		setMaximumSize(new java.awt.Dimension(1050, 375));
		setMinimumSize(new java.awt.Dimension(1050, 375));
		setPreferredSize(new java.awt.Dimension(1056, 410));

		jLabelNumero = new javax.swing.JLabel();
		jTextFieldNumero = new javax.swing.JTextField();
		jLabel1 = new javax.swing.JLabel();
		jTextFieldReference = new javax.swing.JTextField();
		jLabelUserCreator = new javax.swing.JLabel();
		jTextFieldUserCreator = new javax.swing.JTextField();
		jLabelMontant = new javax.swing.JLabel();
		jTextFieldMontant = new javax.swing.JTextField();
		jLabelType = new javax.swing.JLabel();
		jLabelDateCreation = new javax.swing.JLabel();
		jDateChooser1 = new com.toedter.calendar.JDateChooser();
		jLabelDateEcheanche = new javax.swing.JLabel();
		jDateChooser2 = new com.toedter.calendar.JDateChooser();
		jLabelDateExacte = new javax.swing.JLabel();
		jDateChooser3 = new com.toedter.calendar.JDateChooser();
		jComboBox1 = new javax.swing.JComboBox();
		buttonValier = new javax.swing.JButton();
		buttonAnnuler = new javax.swing.JButton();

		setBackground(new java.awt.Color(128, 130, 133));
		setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1,
				new java.awt.Color(123, 153, 255)));

		jLabelNumero.setForeground(new java.awt.Color(255, 255, 255));
		jLabelNumero.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabelNumero.setText("Numero :");

		jTextFieldNumero.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jTextFieldNumeroActionPerformed(evt);
			}
		});
		jLabel1.setForeground(new java.awt.Color(255, 255, 255));
		jLabel1.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabel1.setText("Référence :");

		jLabelUserCreator.setForeground(new java.awt.Color(255, 255, 255));
		jLabelUserCreator.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabelUserCreator.setText("Responsable :");

		jLabelMontant.setForeground(new java.awt.Color(255, 255, 255));
		jLabelMontant.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabelMontant.setText("Montant :");

		jLabelType.setForeground(new java.awt.Color(255, 255, 255));
		jLabelType.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabelType.setText("Type :");

		jLabelDateCreation.setForeground(new java.awt.Color(255, 255, 255));
		jLabelDateCreation.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabelDateCreation.setText("Date Creation :");

		jLabelDateEcheanche.setForeground(new java.awt.Color(255, 255, 255));
		jLabelDateEcheanche.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabelDateEcheanche.setText("Date Echéanche :");

		jLabelDateExacte.setForeground(new java.awt.Color(255, 255, 255));
		jLabelDateExacte.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jLabelDateExacte.setText("Date Exacte :");

		jComboBox1.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"Type", "Commande", "Reception", "Facture", "Devis" }));

		buttonValier.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		buttonValier.setText("Valider");
		buttonValier.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub

				boolean areEmpty;
				int indexe = -1;
				areEmpty = false;
				if (jComboBox1.getSelectedItem().equals("Type")) {
					indexe = 0;
				} else if (jComboBox1.getSelectedItem().equals("Commande")) {
					indexe = 1;

				} else if (jComboBox1.getSelectedItem().equals("Reception")) {
					indexe = 2;
				} else if (jComboBox1.getSelectedItem().equals("Facture")) {
					indexe = 3;
				} else if (jComboBox1.getSelectedItem().equals("Devis")) {
					indexe = 4;
				} else {
					indexe = -1;
				}
				areEmpty = (!jTextFieldNumero.getText().isEmpty()
						&& !jTextFieldMontant.getText().isEmpty()
						&& !jTextFieldReference.getText().isEmpty()
						&& !(indexe == -1) && !(indexe == 0));
				if (!areEmpty) {

					JOptionPane.showMessageDialog(buttonValier,
							"certains champs sont obligatoires");
				} else {
					if (JOptionPane.showConfirmDialog(getFrame(),
							"Voulez-vous vraiment confirmer l'ajout ?",
							"Information", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
						entreeMetier = new EntreesMetier();
						entreeMetier.addEntrees(
								jDateChooser1.getDate(),
								jTextFieldUserCreator.getText(),
								(String) jComboBox1.getSelectedItem(),
								Double.parseDouble(jTextFieldMontant.getText()),
								jDateChooser2.getDate(),
								jDateChooser3.getDate(),
								jTextFieldNumero.getText(),
								jTextFieldReference.getText());

						JOptionPane.showMessageDialog(null,
								"Une entrée a été bien enregistré ");
						jTextFieldMontant.setText("");
						jTextFieldNumero.setText("");
						jTextFieldReference.setText("");
						jTextFieldNumero.setText("");
						jDateChooser1.setDate(null);
						jDateChooser2.setDate(null);
						jDateChooser3.setDate(null);

					}

				}

			}
		});

		buttonAnnuler.setFont(new java.awt.Font("Verdana", 3, 14)); // NOI18N
		buttonAnnuler.setText("Annuler");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap(99, Short.MAX_VALUE)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(
														jLabelType,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														95,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														jLabelDateEcheanche)
												.addComponent(jLabelUserCreator)
												.addComponent(jLabelNumero))
								.addGap(26, 26, 26)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
																.addComponent(
																		jDateChooser2,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		163,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addComponent(
																		jComboBox1,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		167,
																		javax.swing.GroupLayout.PREFERRED_SIZE))
												.addComponent(
														jTextFieldUserCreator,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														167,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														jTextFieldNumero,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														167,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(150, 150, 150)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING,
												false)
												.addGroup(
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jLabelDateExacte,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						117,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jLabelDateCreation))
																.addGap(18, 18,
																		18)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jDateChooser3,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						167,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jDateChooser1,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						167,
																						javax.swing.GroupLayout.PREFERRED_SIZE)))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabelMontant,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		117,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addGap(18, 18,
																		18)
																.addComponent(
																		jTextFieldMontant,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		167,
																		javax.swing.GroupLayout.PREFERRED_SIZE))
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		jLabel1)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		Short.MAX_VALUE)
																.addComponent(
																		jTextFieldReference,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		166,
																		javax.swing.GroupLayout.PREFERRED_SIZE)))
								.addGap(169, 169, 169))
				.addGroup(
						layout.createSequentialGroup().addGap(319, 319, 319)
								.addComponent(buttonValier)
								.addGap(253, 253, 253)
								.addComponent(buttonAnnulers)
								.addGap(163, 163, 163)));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						javax.swing.GroupLayout.Alignment.TRAILING,
						layout.createSequentialGroup()
								.addContainerGap(41, Short.MAX_VALUE)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														jLabel1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														30,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														jTextFieldReference,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														30,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabelNumero)
												.addComponent(
														jTextFieldNumero,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														32,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(37, 37, 37)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														jLabelMontant,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														28,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														jTextFieldMontant,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														28,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(jLabelUserCreator)
												.addComponent(
														jTextFieldUserCreator,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														28,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(35, 35, 35)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														jLabelDateCreation,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														32,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														jLabelType,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														21,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														jComboBox1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														32,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														jDateChooser1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														32,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(17, 17, 17)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.TRAILING)
												.addGroup(
														layout.createSequentialGroup()
																.addGap(27, 27,
																		27)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jLabelDateExacte,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						28,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jDateChooser3,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						29,
																						javax.swing.GroupLayout.PREFERRED_SIZE))
																.addGap(46, 46,
																		46))
												.addGroup(
														javax.swing.GroupLayout.Alignment.LEADING,
														layout.createSequentialGroup()
																.addGap(24, 24,
																		24)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jDateChooser2,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						28,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						jLabelDateEcheanche,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						31,
																						javax.swing.GroupLayout.PREFERRED_SIZE))
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(buttonValier)
												.addComponent(buttonAnnulers))
								.addGap(49, 49, 49)));
	}// </editor-fold>//GEN-END:initComponents

	public javax.swing.JComboBox getjComboBox1() {
		return jComboBox1;
	}

	public void setjComboBox1(javax.swing.JComboBox jComboBox1) {
		this.jComboBox1 = jComboBox1;
	}

	public com.toedter.calendar.JDateChooser getjDateChooser1() {
		return jDateChooser1;
	}

	public void setjDateChooser1(com.toedter.calendar.JDateChooser jDateChooser1) {
		this.jDateChooser1 = jDateChooser1;
	}

	public com.toedter.calendar.JDateChooser getjDateChooser2() {
		return jDateChooser2;
	}

	public void setjDateChooser2(com.toedter.calendar.JDateChooser jDateChooser2) {
		this.jDateChooser2 = jDateChooser2;
	}

	public com.toedter.calendar.JDateChooser getjDateChooser3() {
		return jDateChooser3;
	}

	public void setjDateChooser3(com.toedter.calendar.JDateChooser jDateChooser3) {
		this.jDateChooser3 = jDateChooser3;
	}

	public javax.swing.JTextField getjTextFieldMontant() {
		return jTextFieldMontant;
	}

	public void setjTextFieldMontant(javax.swing.JTextField jTextFieldMontant) {
		this.jTextFieldMontant = jTextFieldMontant;
	}

	public javax.swing.JTextField getjTextFieldNumero() {
		return jTextFieldNumero;
	}

	public void setjTextFieldNumero(javax.swing.JTextField jTextFieldNumero) {
		this.jTextFieldNumero = jTextFieldNumero;
	}

	public javax.swing.JTextField getjTextFieldReference() {
		return jTextFieldReference;
	}

	public void setjTextFieldReference(
			javax.swing.JTextField jTextFieldReference) {
		this.jTextFieldReference = jTextFieldReference;
	}

	public javax.swing.JTextField getjTextFieldUserCreator() {
		return jTextFieldUserCreator;
	}

	public void setjTextFieldUserCreator(
			javax.swing.JTextField jTextFieldUserCreator) {
		this.jTextFieldUserCreator = jTextFieldUserCreator;
	}

	public JPanel getFrame() {
		return this;

	}

	private void jTextFieldNumeroActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jTextFieldNumeroActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_jTextFieldNumeroActionPerformed

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton buttonAnnuler;
	private javax.swing.JButton buttonValier;
	private javax.swing.JComboBox jComboBox1;
	private com.toedter.calendar.JDateChooser jDateChooser1;
	private com.toedter.calendar.JDateChooser jDateChooser2;
	private com.toedter.calendar.JDateChooser jDateChooser3;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabelDateCreation;
	private javax.swing.JLabel jLabelDateEcheanche;
	private javax.swing.JLabel jLabelDateExacte;
	private javax.swing.JLabel jLabelMontant;
	private javax.swing.JLabel jLabelNumero;
	private javax.swing.JLabel jLabelType;
	private javax.swing.JLabel jLabelUserCreator;
	private javax.swing.JTextField jTextFieldMontant;
	private javax.swing.JTextField jTextFieldNumero;
	private javax.swing.JTextField jTextFieldReference;
	private javax.swing.JTextField jTextFieldUserCreator;
	// End of variables declaration//GEN-END:variables
}
